def is_valid(s: str) -> bool:
    brackets = {"(": ")", "[": "]", "{": "}", "<": ">"}
    stack = []

    for char in s.replace(" ", ""):
        if char in brackets:
            stack.append(char)
        else:
            if not stack or brackets[stack.pop()] != char:
                return False

    return not stack


print(is_valid(input("Введите последовательность: ")))
